package com.hardydou.system.controller;

import com.hardydou.common.result.Result;
import com.hardydou.common.controller.BaseController;
import com.hardydou.common.result.ResultHelper;
import com.hardydou.system.model.LoginUserDetails;
import com.hardydou.system.model.SystemConfig;
import com.hardydou.system.model.SystemRes;
import com.hardydou.system.service.ISystemConfigService;
import com.hardydou.system.service.ISystemResService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author ：hardy
 * @description：
 * @date ：Created in 2020/6/2
 * @Copyright ：Hardydou.com
 */
@Controller
@Api(tags = "菜单管理")
public class SysMenuController extends BaseController {
    @Autowired
    ISystemResService resService;

    @Autowired
    ISystemConfigService configService;

    @GetMapping("/system/menu.json")
    @ResponseBody
    public Result menu() {
        LoginUserDetails loginUser = getLoginUserDetails();
        Result<Map<String, Object>> result = ResultHelper.ok();
        Map tmp = result.getData();
        List<SystemRes> menus = loginUser.getSystemUser().getResList();
        tmp.put("menus", menus);
        SystemConfig menuLevelConfig = configService.findByConfigKey("system.menu.level");
        if (menuLevelConfig != null) {
            tmp.put("level", Long.parseLong(menuLevelConfig.getConfigValue()));
        }
        return result;
    }
}
